Skip to content

Conversation

@AlixBa
Copy link
Contributor

@AlixBa AlixBa commented Dec 26, 2025

In order to avoid this, as both _INBOX and _R_ are used for temporary request/reply subjects.
Screenshot 2025-12-26 at 19 20 05

It can also be useful for internal operations. On my side I use custom subjects for warming up my application, _TEMP.warmup.UUID. They pop-up in the span names and as I use a UUID I'd like to rename these ones to (temporary) too.

@AlixBa AlixBa requested a review from a team as a code owner December 26, 2025 18:22
}

@Override
public boolean isHelperClass(String className) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do I understand correctly that this isn't really needed for the javaagent instrumentation to function since this class is only used by the library instrumentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but Muzzle complained because the package of the OpenTelemetryDispatcherFactory is set to io.nats.client.impl. to access package-private classes.

[otel.javaagent 2025-12-26 18:28:06:156 +0000] [Test worker] 
WARN io.opentelemetry.javaagent.tooling.instrumentation.MuzzleMatcher - 
Instrumentation skipped, mismatched references were found: nats 
[class io.opentelemetry.javaagent.instrumentation.nats.v2_17.NatsInstrumentationModule] on sun.misc.Launcher$AppClassLoader@73d16e93


[otel.javaagent 2025-12-26 18:28:06:176 +0000] [Test worker] 
WARN io.opentelemetry.javaagent.tooling.instrumentation.MuzzleMatcher - 
-- io.opentelemetry.javaagent.shaded.instrumentation.nats.v2_17.NatsTelemetry:66 
Missing method io.nats.client.impl.OpenTelemetryDispatcherFactory#<init>(
  Lio/nats/client/impl/DispatcherFactory;
  Lio/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/Instrumenter;
)V

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just curios why it wasn't needed previously. Can't spot what in the current PR requires adding it, but otherwise I'm fine with adding it.


/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time. Exposed for {@link io.nats.client.impl.OpenTelemetryDispatcherFactory}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand Exposed for {@link io.nats.client.impl.OpenTelemetryDispatcherFactory}.. This class isn't used by OpenTelemetryDispatcherFactory as far as I can tell.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad copy/paste 😬


public static Pattern compile(String subject) {
return Pattern.compile(
"^" + subject.replace(".", "\\.").replace(">", "*").replace("*", ".*") + "$");
Copy link
Contributor

@laurit laurit Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none of the tests fail when replace(">", "*") is removed

* @param temporaryPatterns A list of patterns.
*/
@CanIgnoreReturnValue
public NatsTelemetryBuilder setTemporaryPatterns(Collection<Pattern> temporaryPatterns) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it would be better to let users specify prefixes for temporary subjects? Or do you believe there are use cases where the more powerful matching capability of regex is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know all usages but it might not always be prefixes. I guess one could use some.*.temporary.subject.> as the doc allows usage of both * and >. We can start with prefixes if it's simpler.

* @param temporarySubjects A list of subjects.
*/
@CanIgnoreReturnValue
public NatsTelemetryBuilder setTemporarySubjects(Collection<String> temporarySubjects) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo in its current for too much effort is needed to understand what this method does and how it differs from setTemporaryPatterns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted a nats-friendly API where you specify the temp subjects the same way you'd do them in NATS. But This can be removed of course

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be best to document stuff like that. You should not expect people reading the code really know what kind of wildcards nats uses and to me it feels very unlikely that anybody looking at this method can figure out that it accepts that kind of wildcards.

*/
private Pattern getTemporaryPattern(NatsRequest request) {
if (request.getSubject().startsWith(request.getInboxPrefix())) {
return NatsSubjectPattern.compile(request.getInboxPrefix() + "*");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels inefficient

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfomance wise?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I suspect you could avoid compiling the regular expression

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants